<?php
namespace App\Http\Controllers\Qr;


use App\Api\Controllers\Config\AlipayIsvConfigController;
use App\Api\Controllers\Config\LinkageConfigController;
use App\Api\Controllers\Config\PayWaysController;
use App\Api\Controllers\Config\VbillConfigController;
use App\Api\Controllers\Config\WeixinConfigController;
use App\Api\Controllers\Hltx\ManageController;
use App\Api\Controllers\Vbill\PayController;
use App\Http\Controllers\Controller;
use App\Models\HltxStore;
use App\Models\QrCodeHb;
use App\Models\QrPayInfo;
use App\Models\Store;
use App\Models\StorePayWay;
use App\Models\TfStore;
use App\Models\User;
use App\Models\WeixinConfig;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\URL;

class QrController extends Controller
{
    //多码合一
    public function qr(Request $request)
    {
        //可以传门店、收银员、支付渠道、
        $no = $request->get('no');//码编号
        $store_id = $request->get('store_id', '');//门店ID
        $merchant_id = $request->get('merchant_id', '');//收银员
        $company = $request->get('company', '');//支付渠道公司
        $other_no = $request->get('other_no', '');//收银员
        $notify_url = $request->get('notify_url', '');//收银员

        $url = $request->url();
        $is_https = substr($url, 0, 5);

        if($request->server()["SERVER_NAME"] == "admin.zgjindoufu.com"){
            $url = $request->server();
            return redirect('https://' . "pay.zgjindoufu.com". $url['REQUEST_URI']);
        }
        if ($is_https != "https") {
            $url = $request->server();
            return redirect('https://' . $url['SERVER_NAME'] . $url['REQUEST_URI']);
        }
        //门店ID 为空 编号不能为空
        if ($store_id == "") {
            //编号不能为空
            if ($no == "") {
                $message = "空码编号或者门店ID不能为空";
                return view('errors.page_errors', compact('message'));
            }
            $qr = Cache::get($no);
            //$qr = false;
            if (!$qr) {
                $qr = QrPayInfo::where('code_number', $no)
                    ->select('*')
                    ->first();
                Cache::put($no, $qr, 1);
            }

            if (!$qr) {
                $message = "码没有绑定激活";
                return view('errors.page_errors', compact('message'));
            }

            $store_id = $qr->store_id;
            $merchant_id = $qr->merchant_id;
        }

        if ($store_id) {
            $pay_type = "unionpay";
            //判断是不是微信
            if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
                $pay_type = 'weixin';
            }

            //判断是不是支付宝
            if (strpos($_SERVER['HTTP_USER_AGENT'], 'AlipayClient') !== false) {
                $pay_type = 'alipay';
            }

            //判断是不是翼支付
            if (strpos($_SERVER['HTTP_USER_AGENT'], 'Bestpay') !== false) {
                $pay_type = 'Bestpay';
            }
            

            //判断是不是京东
            if (strpos($_SERVER['HTTP_USER_AGENT'], 'WalletClient') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'JDJR-App') !== false) {
                $pay_type = 'jd';
            }

            if (strpos($_SERVER['HTTP_USER_AGENT'], 'WalletClient') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'jdapp') !== false) {
                $pay_type = 'jd';
            }

            $where = [];
            $where[] = ['ways_source', '=', $pay_type];
            $where[] = ['store_id', '=', $store_id];

            //缓存
            // $store = Cache::get($store_id . 'qr-pay');
            // if (!$store) {
                $store = Store::where('store_id', $store_id)
                    ->select('config_id', 'user_id', 'pid', 'merchant_id', 'store_short_name', 'store_address')
                    ->first();

                //Cache::put($store_id . 'qr-pay', $store, 1000);
            // }

            if (!$store) {
                $message = "门店不存在";

                return view('errors.page_errors', compact('message'));
            }

            $store_pid = $store->pid;
            $user_id = $store->user_id;
            $obj_ways = new PayWaysController();
            $StorePayWay = $obj_ways->ways_source($pay_type, $store_id, $store_pid);
            if(empty($StorePayWay)){
                $pid = Store::where('store_id', $store_id)->select('pid')->first();
                $store_pid=$pid->pid;
                $StorePayWay =$obj_ways->ways_source($pay_type, $store_id, $store_pid);
            }


            $user = User::where('id', $user_id)->select('id', 'is_delete')->first();
            if (!$user) {
                $message = "业务员被删除，请联系归属业务员";

                return view('errors.page_errors', compact('message'));
            }

            if ($user->is_delete) {
                $message = "业务员被删除，请联系归属业务员";

                return view('errors.page_errors', compact('message'));
            }
            if ($company) {
                $StorePayWay = $obj_ways->company_ways_source($company, $pay_type, $store_id, $store_pid);
            }

            if (!$StorePayWay) {
                $message = "没有找到合适的支付方式";

                return view('errors.page_errors', compact('message'));
            }
            //验证扣费模式
            list($isRun,$error)=\App\Services\Store\StoreSignService::validateSign((string)$StorePayWay->store_id,(string)$StorePayWay->company);
            if($isRun==false){
                $message = $error;
                return view('errors.page_errors', compact('message'));
            }

            $ways_type = $StorePayWay->ways_type;
            

            //商户id为空
            if ($merchant_id == "") {
                $merchant_id = $store->merchant_id;
            }

            //配置
            $state = [
                'store_id' => $store_id,
                'store_name' => $store->store_short_name,
                'store_address' => $store->store_address,
                'config_id' => $store->config_id,
                'merchant_id' => $merchant_id,
                'auth_type' => '02',
                'other_no' => $other_no,
                'notify_url' => $notify_url,
                'store_pid' => $store_pid
            ];
            

            //支付宝
            if ($pay_type == 'alipay') {
                $isvconfig = new AlipayIsvConfigController();
                $config = $isvconfig->AlipayIsvConfig($store->config_id);

                //官方支付宝
                if ($ways_type == 1000) {
                    $state['bank_type'] = 'alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;

                    return redirect($code_url);
                }

                //网商支付宝
                if ($ways_type == 3001) {
                    $state['bank_type'] = 'mbalipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;

                    return redirect($code_url);
                }

                //京东支付支付宝
                if ($ways_type == 6001) {
                    $state['bank_type'] = 'jdalipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;

                    return redirect($code_url);
                }

                //新大陆支付宝
                if ($ways_type == 8001) {
                    $state['bank_type'] = 'nlalipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;

                    return redirect($code_url);
                }

                //会员宝支付宝
                if ($ways_type == 9001) {
                    $state['bank_type'] = 'halipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;

                    return redirect($code_url);
                }

                //联拓富支付支付宝
                if ($ways_type == 10001) {
                    $state['bank_type'] = 'lftalipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;

                    return redirect($code_url);
                }

                //富有支付宝
                if ($ways_type == 11001) {
                    $state['bank_type'] = 'fuioualipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;

                    return redirect($code_url);
                }

                //哆啦宝支付宝
                if ($ways_type == 15001) {
                    $state['bank_type'] = 'dlb_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;

                    return redirect($code_url);
                }

                //传化支付宝
                if ($ways_type == 12001) {
                    $state['bank_type'] = 'tfpay_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;

                    return redirect($code_url);
                }

                //随行付支付宝
                if ($ways_type == 13001) {
                    $state['bank_type'] = 'vbill_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;
                    return redirect($code_url);
                }
                
                //翼支付支付宝
                if ($ways_type == 30051) {
                    $state['bank_type'] = 'wing_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;
                    return redirect($code_url);
                }
                
                //平安银行支付宝
                if ($ways_type == 30012) {
                    $state['bank_type'] = 'safe_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;
                    return redirect($code_url);
                }
		
		        //汇付-支付宝
                if ($ways_type == 18001) {
                    $state['bank_type'] = 'huipay_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;
//                    Log::info('alipay_url: '.$code_url);

                    return redirect($code_url);
                }

                //随行付a支付宝
                if ($ways_type == 19001) {
                    $state['bank_type'] = 'vbilla_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;

                    return redirect($code_url);
                }
		
		        //海科融通 支付宝
                if ($ways_type == 22001) {
                    $state['bank_type'] = 'hkrt_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;

                    return redirect($code_url);
                }

                //易生支付 支付宝
                if ($ways_type == 21001 || $ways_type == 61001) {
                    if($ways_type == 61001){
                        $state['bank_type'] = 'easypaya_alipay';
                    }else{
                        $state['bank_type'] = 'easypay_alipay';
                    }
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;

                    return redirect($code_url);
                }

                //联动优势支付宝
                if ($ways_type == 5001) {
                    $state['bank_type'] = 'linkage_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;

                    return redirect($code_url);
                }

                //直付通支付宝
                if ($ways_type == 16002) {
                    $state['bank_type'] = 'zft_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;

                    return redirect($code_url);
                }

                //葫芦天下支付宝
                if ($ways_type == 23001) {
                    $state['bank_type'] = 'hltx_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;

                    return redirect($code_url);
                }

                //威富通 支付宝
                if ($ways_type == 27001) {
                    $state['bank_type'] = 'wftpay_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;

                    return redirect($code_url);
                }


                //威富通 支付宝
                if ($ways_type == 27101) {
                    $state['bank_type'] = 'wftpayv2_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;

                    return redirect($code_url);
                }

                //汇旺财 支付宝
                if ($ways_type == 28001) {
                    $state['bank_type'] = 'hwcpay_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;

                    return redirect($code_url);
                }
                
                //邮储银行 支付宝
                if ($ways_type == 26001) {
                    $state['bank_type'] = 'you_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;
                    return redirect($code_url);
                }
                
                // 九江银行 支付宝
                if ($ways_type == 37002) {
                    
                    $state['bank_type'] = 'jiujiang_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;
                    // print_r($code_url);die;
                    return redirect($code_url);
                }
                
                //工行 支付宝
                if ($ways_type == 20001) {
                    $state['bank_type'] = 'icbc_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/vbill/weixin/icbc_alioauth?state=' . $state);

                    return redirect($code_url);
                }
                
                // 银卡 支付宝
                if ($ways_type == 38002) {

                    $state['bank_type'] = 'yinka_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;
                    // print_r($code_url);die;
                    return redirect($code_url);
                }
                
                 // 兴业银行 支付宝
                if ($ways_type == 39002) {

                    $state['bank_type'] = 'cib_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;
                    // print_r($code_url);die;
                    return redirect($code_url);
                }

                // 民生银行 支付宝
                if ($ways_type == 50002) {
                    $state['bank_type'] = 'cmbc_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;
                    return redirect($code_url);
                }

                //国通支付 支付宝 已新增v2
                if (in_array($ways_type , [62001,62011])) {
                    $state['bank_type'] = 'gtxy_alipay';
                    if($ways_type==62011){
                        $state['bank_type'] = 'gtxy_v2_alipay';
                    }
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;

                    return redirect($code_url);
                }



                // TODO[银盛支付:支付宝入口]
                if ($ways_type == 14001) {
                    $state['bank_type'] = 'yinsheng_alipay';
                    Log::info('银盛支付:支付宝入口',$state);
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;
                    Log::info('银盛支付:支付宝入口',[$code_url]);
                    return redirect($code_url);
                }

                // TODO[东莞银行:支付宝入口]
                if ($ways_type == 40002) {
                    $state['bank_type'] = 'dongguan_alipay';
                    $state = \App\Common\TransFormat::encode($state);
                    $app_auth_url = $config->alipay_app_authorize;
                    $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;
                    return redirect($code_url);
                }

            }

            //微信
            if ($pay_type == 'weixin') {
                $config = new WeixinConfigController();
                $WeixinConfig = $config->weixin_config_obj($store->config_id);
                if (!$WeixinConfig) {
                    $message = "微信配置不存在~";
                    return view('errors.page_errors', compact('message'));
                }
                $config_type = $WeixinConfig->config_type;

                $weixin_merchant_obj = $config->weixin_merchant($store->store_id);

                $code_url = '';
                
                // print_r($ways_type);die;
                
                //联动优势 微信支付
                if ($ways_type == 5002) {
                    $state['bank_type'] = 'linkage_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;
                    
                   
                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/linkage/weixin/oauth?state=' . $state);

                    return redirect($code_url);
                }
                
                //官方微信支付
                if ($ways_type == 2000) {
                    $state['bank_type'] = 'weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;
                    if ($weixin_merchant_obj && $weixin_merchant_obj->is_profit_sharing) {
                        $state['is_profit_sharing'] = true;
                    }

                    //开放平台代替授权
                    if ($config_type == "2") {
                        $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
                        $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/weixinopen/oauth?state=' . $state);

                        return redirect($code_url);
                    } //服务商特约
                    else {
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/weixin/oauth?state=' . $state);

                        return redirect($code_url);
                    }
                }

                //官方微信支付a
                if ($ways_type == 4000) {
                    $state['bank_type'] = 'weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    $weixin_merchant_obj = $config->weixina_merchant($store->store_id);
                    if ($weixin_merchant_obj && $weixin_merchant_obj->is_profit_sharing) {
                        $state['is_profit_sharing'] = true;
                    }

                    //开放平台代替授权
                    if ($config_type == "2") {
                        $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
                        $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/weixinopen/oautha?state=' . $state);

                        return redirect($code_url);
                    } //服务商特约
                    else {
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/weixin/oautha?state=' . $state);

                        return redirect($code_url);
                    }
                }

                //快钱微信支付
                if ($ways_type == 3002) {
                    //走想用渠道
                    $array = [
                        'https://dl.shouqianloupay.cn',
                        'https://x.xdspay.com',
                        'https://pay.ycfgd.com',
                        'https://pay.umxnt.com',
                        'https://pay.shouqupay.com',
                        'https://ss.tonlot.com',
                        'https://yb.xiangyongpay.com',
                        'https://pay.fuya18.com',
                        'https://pay.mynkj.cn',
                        'https://yh.yihoupay.com',
                        'https://pay.hsfpay.com',
                        'https://yf.hzbinfan.com',
                        'https://fyb.umxnt.com',
                        'https://pay.saomafupay.com',
                        'https://pay.zhekoulou.com',
                        'https://fu.shualianfu.wang',
                        'https://x.woyoupos.com',
                        'https://hsf.umxnt.com',
                        'https://msf.umxnt.com',
                        'https://pay.shualianpay.com.cn',
                        'https://www.s1spay.com',
                        'https://pay.shanghaiyif.com',
                        'https://pay.dgjgd168.com',
                        'https://pay.judianbang1688.com',
                        'https://www.yunsoyi.cn',
                        'https://yunfu.yuzewangluokeji.com',
                        'https://pay.wzhy815.com',
                        'https://p.unistoneits.com',
                        'https://pay.xiangyongkeji.cn',
                        'https://pay.baidexun.com',
                        'https://x.thewind.com.cn',
                        'https://qht.qdshsh.com',
                        'https://smile.hongzhoukeji.com',
                        'https://ririfu.shishifuba.com',
                        'https://payment.yinboxx.com',
                        'https://pay.ruoxinpay.com',
                        'https://pay.mefancy.cn',
                        'https://pay.yunmuzf.com',
                        'https://pay.kanyiyan.net',
                        'https://kzf.xiangyongpay.com',
                        'https://b.lefu.run',
                        'https://b.ymgyee.cn',
                        'https://pay.zcxxkj.top',
                        'https://pay.qingsongfu.net',
                        'https://pay.slzfsh.com',
                        'https://pay.caochaochao.com',
                        'https://sm.pinyougaoxiao.com',
                        'https://pay.mfbisv.com',
                        'https://pays.hnsxpay.com',
                        'https://sly.umxnt.com',
                        'https://pay.qiaobei.co',
                        'https://sm.pinyougaoxiao.com',
                        'https://pay.huachengxulong.com',
                        'https://cps.afpay.cn',
                        'https://515151ufo.cn'
                    ];

                    if (in_array(url(''), $array)) {
                        //看下配置是不是想用网商的是的话就去想用那边拿openID
                        $config_type = '3';//需要使用想用网商微信的其他独立平台
                    }

                    $state['bank_type'] = 'mybank_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    //开放平台代替授权
                    if ($config_type == "2") {
                        $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
                        $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/weixinopen/oauth?state=' . $state);

                        return redirect($code_url);
                    } elseif ($config_type == "3") {
                        //跳转到想用去获取openid
                        $state['callback_url'] = url('/api/mybank/weixin/pay_view');
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = 'https://x.umxnt.com/api/mybank/weixin/oauth_openid?state=' . $state;

                        return redirect($code_url);
                    } //服务商特约
                    else {
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/mybank/weixin/oauth?state=' . $state);

                        return redirect($code_url);
                    }
                }

                //京东微信支付
                if ($ways_type == 6002) {
                    $state['bank_type'] = 'jd_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    //开放平台代替授权
                    if ($config_type == "2") {
                        $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
                        $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/weixinopen/oauth?state=' . $state);

                        return redirect($code_url);
                    } //服务商特约
                    else {
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/jd/weixin/oauth?state=' . $state);

                        return redirect($code_url);
                    }
                }

                //新大陆微信支付
                if ($ways_type == 8002) {
                    $state['bank_type'] = 'nl_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    //开放平台代替授权
                    if ($config_type == "2") {
                        $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
                        $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/weixinopen/oauth?state=' . $state);

                        return redirect($code_url);
                    } //服务商特约
                    else {
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/newland/weixin/oauth?state=' . $state);

                        return redirect($code_url);
                    }
                }

                //和融通微信支付
                if ($ways_type == 9002) {
                    $array = [
                        'https://pay.ycfgd.com',
                        'https://pay.umxnt.com',
                        'https://pay.shouqupay.com',
                        'https://ss.tonlot.com',
                        'https://yb.xiangyongpay.com',
                        'https://pay.fuya18.com',
                        'https://pay.mynkj.cn',
                    ];
                    //走想用渠道的商户
                    if (in_array(url(''), $array)) {
                        //看下配置是不是想用和融通的是的话就去想用那边拿openID
                        //$StorePayWay

                        //以前用的还是想用的渠道
                        $created_at = $StorePayWay->created_at;
                        if ($created_at < '2019-06-21 12:00:00') {
                            $config_type = '3';//需要使用想用和融通微信的其他独立平台
                        } else {
                            //用和融通的渠道
                        }
                    }

                    $state['bank_type'] = 'h_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    //开放平台代替授权
                    if ($config_type == "2") {
                        $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
                        $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/weixinopen/oauth?state=' . $state);

                        return redirect($code_url);
                    } elseif ($config_type == "3") {
                        //跳转到想用去获取openid
                        $state['callback_url'] = url('/api/huiyuanbao/weixin/pay_view');
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = 'https://pay.umxnt.com/api/huiyuanbao/weixin/oauth_openid?state=' . $state;

                        return redirect($code_url);
                    } //服务商特约
                    else {
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/huiyuanbao/weixin/oauth?state=' . $state);

                        return redirect($code_url);
                    }
                }

                //微信支付
                if ($ways_type == 10002) {
                    $state['bank_type'] = 'ltf_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    //开放平台代替授权
                    if ($config_type == "2") {
                        $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
                        $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/weixinopen/oauth?state=' . $state);

                        return redirect($code_url);
                    } //服务商特约
                    else {
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/ltf/weixin/oauth?state=' . $state);

                        return redirect($code_url);
                    }
                }

                //富友微信支付
                if ($ways_type == 11002) {
                    $state['bank_type'] = 'fuioy_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    //开放平台代替授权
                    if ($config_type == "2") {
                        $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
                        $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/weixinopen/oauth?state=' . $state);

                        return redirect($code_url);
                    } //服务商特约
                    else {
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/fuiou/weixin/oauth?state=' . $state);

                        return redirect($code_url);
                    }
                }

                //哆啦宝微信支付
                if ($ways_type == 15002) {
                    $state['bank_type'] = 'dlb_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;
                    //开放平台代替授权
                    if ($config_type == "2") {
                        $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
                        $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/dlb/weixinopen/oauth?state=' . $state);

                        return redirect($code_url);
                    } //服务商特约
                    else {
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/dlb/weixin/oauth?state=' . $state);

                        return redirect($code_url);
                    }
                }

                //传化微信支付
                if ($ways_type == 12002) {
                    $state['bank_type'] = 'tfpay_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    //走想用渠道
                    $array = [
                        'https://dl.shouqianloupay.cn',
                        'https://x.xdspay.com',
                        'https://pay.ycfgd.com',
                        'https://pay.umxnt.com',
                        'https://pay.shouqupay.com',
                        'https://ss.tonlot.com',
                        'https://yb.xiangyongpay.com',
                        'https://pay.fuya18.com',
                        'https://pay.mynkj.cn',
                        'https://yh.yihoupay.com',
                        'https://pay.hsfpay.com',
                        'https://yf.hzbinfan.com',
                        'https://fyb.umxnt.com',
                        'https://pay.saomafupay.com',
                        'https://pay.zhekoulou.com',
                        'https://fu.shualianfu.wang',
                        'https://x.woyoupos.com',
                        'https://hsf.umxnt.com',
                        'https://msf.umxnt.com',
                        'https://pay.shualianpay.com.cn',
                        'https://www.s1spay.com',
                        'https://pay.shanghaiyif.com',
                        'https://pay.dgjgd168.com',
                        'https://pay.judianbang1688.com',
                        'https://www.yunsoyi.cn',
                        'https://yunfu.yuzewangluokeji.com',
                        'https://pay.wzhy815.com',
                        'https://p.unistoneits.com',
                        'https://pay.xiangyongkeji.cn',
                        'https://pay.baidexun.com',
                        'https://x.thewind.com.cn',
                        'https://qht.qdshsh.com',
                        'https://smile.hongzhoukeji.com',
                        'https://ririfu.shishifuba.com',
                        'https://payment.yinboxx.com',
                        'https://pay.ruoxinpay.com',
                        'https://pay.mefancy.cn',
                        'https://pay.yunmuzf.com',
                        'https://pay.kanyiyan.net',
                        'https://kzf.xiangyongpay.com',
                        'https://b.lefu.run',
                        'https://b.ymgyee.cn',
                        'https://pay.zcxxkj.top',
                        'https://pay.qingsongfu.net',
                        'https://pay.slzfsh.com',
                        'https://pay.caochaochao.com',
                        'https://sm.pinyougaoxiao.com',
                        'https://pay.mfbisv.com',
                        'https://pays.hnsxpay.com',
                        'https://sly.umxnt.com',
                        'https://pay.qiaobei.co',
                        'https://sm.pinyougaoxiao.com',
                        'https://pay.huachengxulong.com',
                        'https://cps.afpay.cn',
                        'https://515151ufo.cn'
                    ];

                    $qd = 1;
                    $TfStore = TfStore::where('store_id', $store_id)
                        ->select('qd')
                        ->first();
                    if ($TfStore) {
                        $qd = $TfStore->qd;
                    }
                    $state['qd'] = $qd;

                    if (in_array(url(''), $array) && $qd == 1) {
                        //看下配置是不是想用网商的是的话就去想用那边拿openID
                        $config_type = '3';//需要使用想用网商微信的其他独立平台
                    }

                    //开放平台代替授权
                    if ($config_type == "2") {
                        $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
                        $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/tfpay/weixinopen/oauth?state=' . $state);

                        return redirect($code_url);
                    } elseif ($config_type == "3") {
                        //跳转到想用去获取openid
                        $state['callback_url'] = url('/api/tfpay/weixin/pay_view');
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = 'https://x.umxnt.com/api/mybank/weixin/oauth_openid?state=' . $state;

                        return redirect($code_url);
                    } //服务商特约
                    else {
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/tfpay/weixin/oauth?state=' . $state);

                        return redirect($code_url);
                    }
                }

                //随行付微信支付
                if ($ways_type == 13002) {
                    $state['bank_type'] = 'vbill_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;
                    //开放平台代替授权
                    if ($config_type == "2") {
                        $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
                        $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/vbill/weixinopen/oauth?state=' . $state);

                        return redirect($code_url);
                    } elseif ($config_type == "3") {
                        //跳转到想用去获取openid
                        $state['callback_url'] = url('/api/vbill/weixin/pay_view');
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = 'https://x.umxnt.com/api/vbill/weixin/oauth_openid?state=' . $state;

                        return redirect($code_url);
                    } //服务商特约
                    else {
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/vbill/weixin/oauth?state=' . $state);

                        return redirect($code_url);
                    }
                }
                
                //翼支付微信支付
                if ($ways_type == 30050) {
                    $state['bank_type'] = 'wingpay_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;
                    //开放平台代替授权
                    if ($config_type == "2") {
                        $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
                        $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/vbill/weixinopen/oauth?state=' . $state);

                        return redirect($code_url);
                    } elseif ($config_type == "3") {
                        //跳转到想用去获取openid
                        $state['callback_url'] = url('/api/vbill/weixin/pay_view');
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = 'https://x.umxnt.com/api/vbill/weixin/oauth_openid?state=' . $state;

                        return redirect($code_url);
                    } //服务商特约
                    else {
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/vbill/weixin/wingoauth?state=' . $state);
                        return redirect($code_url);
                    }
                }
                
                 //邮储银行 微信支付主扫
                if ($ways_type == 26002) {
                    $state['bank_type'] = 'youpay_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;
                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/vbill/weixin/youpayoauth?state=' . $state);
                    return redirect($code_url);
                }
                
                //平安银行 微信支付主扫
                if ($ways_type == 30011) {
                    $state['bank_type'] = 'wingpay_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;
                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/vbill/weixin/safeoauth?state=' . $state);
                    return redirect($code_url);
                }

                //汇付-微信支付
                if ($ways_type == 18002) {
                    $state['bank_type'] = 'huipay_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    //开放平台代替授权
                    if ($config_type == "2") {
                        $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
                        $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/huipay/weixinopen/oauth?state=' . $state);

                        return redirect($code_url);
                    } elseif ($config_type == "3") {
                        //跳转到想用去获取openid
                        $state['callback_url'] = url('/api/huipay/weixin/pay_view');
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = 'https://x.umxnt.com/api/huipay/weixin/oauth_openid?state=' . $state;

                        return redirect($code_url);
                    } //服务商特约
                    else {
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/huipay/weixin/oauth?state=' . $state);

                        return redirect($code_url);
                    }
                }

                //随行付a微信支付
                if ($ways_type == 19002) {
                    $state['bank_type'] = 'vbilla_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    //开放平台代替授权
                    if ($config_type == "2") {
                        $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
                        $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/vbill/weixinopen/oautha?state=' . $state);

                        return redirect($code_url);
                    } elseif ($config_type == "3") {
                        //跳转到想用去获取openid
                        $state['callback_url'] = url('/api/vbill/weixin/pay_viewa');
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = 'https://x.umxnt.com/api/vbill/weixin/oauth_openida?state=' . $state;

                        return redirect($code_url);
                    } //服务商特约
                    else {
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/vbill/weixin/oautha?state=' . $state);

                        return redirect($code_url);
                    }
                }
		
		        //海科融通 微信支付
                if ($ways_type == 22002) {
                    $state['bank_type'] = 'hkrt_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    //开放平台代替授权
                    if ($config_type == "2") {
                        $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
                        $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/hkrt/weixinopen/oautha?state=' . $state);

                        return redirect($code_url);
                    } elseif ($config_type == "3") {
                        //跳转到想用去获取openid
                        $state['callback_url'] = url('/api/hkrt/weixin/pay_viewa');
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = 'https://x.umxnt.com/api/hkrt/weixin/oauth_openida?state=' . $state;

                        return redirect($code_url);
                    } //服务商特约
                    else {
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/hkrt/weixin/oautha?state=' . $state);

                        return redirect($code_url);
                    }
                }

                //易生支付 易生支付a 微信支付
                if ($ways_type == 21002 || $ways_type == 61002) {
                    if($ways_type==61002){
                        $state['bank_type'] = 'easypaya_weixin';
                    }else{
                        $state['bank_type'] = 'easypay_weixin';
                    }

                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    //开放平台代替授权
                    if ($config_type == "2") {
                        $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
                        $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/easypay/weixinopen/oauth?state=' . $state);

                        return redirect($code_url);
                    } elseif ($config_type == "3") {
                        //跳转到想用去获取openid
                        $state['callback_url'] = url('/api/easypay/weixin/pay_viewa');
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = 'https://x.umxnt.com/api/easypay/weixin/oauth_openida?state=' . $state;

                        return redirect($code_url);
                    } //服务商特约
                    else {
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/easypay/weixin/oauth?state=' . $state);

                        return redirect($code_url);
                    }
                }

                //葫芦天下
                if ($ways_type == 23002) {
                    $manager = new \App\Api\Controllers\Hltx\ManageController();
                    $hltx_merchant = $manager->pay_merchant($store_id, $store_pid);

                    $qd = $hltx_merchant->qd;
                    $state['bank_type'] = 'hltx_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;
                    $state['qd'] = $qd;

                    //开放平台代替授权
                    if ($config_type == "2") {
                        $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
                        $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/weixinopen/oauth?state=' . $state);

                        return redirect($code_url);
                    } //服务商特约
                    else {
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/hltx/weixin/oauth?state=' . $state);

                        return redirect($code_url);
                    }
                }

                //威富通 微信支付
                if ($ways_type == 27002) {
                    $state['bank_type'] = 'wftpay_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    //开放平台代替授权
                    if ($config_type == "2") {
                        $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
                        $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/wftpay/weixinopen/oauth?state=' . $state);

                        return redirect($code_url);
                    } elseif ($config_type == "3") {
                        //跳转到想用去获取openid
                        $state['callback_url'] = url('/api/wftpay/weixin/pay_viewa');
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = 'https://x.umxnt.com/api/wftpay/weixin/oauth_openida?state=' . $state;

                        return redirect($code_url);
                    } //服务商特约
                    else {
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/wftpay/weixin/oauth?state=' . $state);

                        return redirect($code_url);
                    }
                }
                //威富通 微信支付
                if ($ways_type == 27102) {
                    $state['bank_type'] = 'wftpayv2_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;
                    //开放平台代替授权
                    if ($config_type == "2") {
                        $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
                        $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/wftpay/weixinopen/oauth?state=' . $state);

                        return redirect($code_url);
                    } elseif ($config_type == "3") {
                        //跳转到想用去获取openid
                        $state['callback_url'] = url('/api/wftpay/weixin/pay_viewa');
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = 'https://x.umxnt.com/api/wftpay/weixin/oauth_openida?state=' . $state;

                        return redirect($code_url);
                    } //服务商特约
                    else {
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/wftpay/weixin/oauth?state=' . $state);

                        return redirect($code_url);
                    }
                }

                //汇旺财 微信支付
                if ($ways_type == 28002) {
                    $state['bank_type'] = 'hwcpay_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    //开放平台代替授权
                    if ($config_type == "2") {
                        $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
                        $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/hwcpay/weixinopen/oauth?state=' . $state);

                        return redirect($code_url);
                    } elseif ($config_type == "3") {
                        //跳转到想用去获取openid
                        $state['callback_url'] = url('/api/hwcpay/weixin/pay_viewa');
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = 'https://x.umxnt.com/api/hwcpay/weixin/oauth_openida?state=' . $state;

                        return redirect($code_url);
                    } //服务商特约
                    else {
                        $state = \App\Common\TransFormat::encode($state);
                        $code_url = url('api/hwcpay/weixin/oauth?state=' . $state);

                        return redirect($code_url);
                    }
                }

                // 九江 微信支付
                if ($ways_type == 37001) {
                    $state['bank_type'] = 'jiujiang_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;
                    
                    
                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/jiujiang/weixin/oauth?state=' . $state);
                    // print_r($code_url);die;
                    return redirect($code_url);
                }
                
                //工行 微信支付
                if ($ways_type == 20002) {
                    $state['bank_type'] = 'icbc_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/vbill/weixin/icbc_oauth?state=' . $state);

                    return redirect($code_url);
                }
                
                 // 银卡 微信支付
                if ($ways_type == 38001) {
                    $state['bank_type'] = 'yinka_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;


                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/yinka/oauth?state=' . $state);
                    // print_r($code_url);die;
                    return redirect($code_url);
                }
                
                // 兴业银行 微信支付
                if ($ways_type == 39001) {
                    $state['bank_type'] = 'cib_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;


                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/cib/weixin/oauth?state=' . $state);
                    // print_r($code_url);die;
                    return redirect($code_url);
                }

                // 民生银行 微信支付
                if ($ways_type == 50001) {
                    $state['bank_type'] = 'cmbc_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;
                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/cmbc/weixin/oauth?state=' . $state);
                    return redirect($code_url);
                }

                //国通 微信支付
                if (in_array($ways_type ,[62002,62012])) {
                    $state['bank_type'] = 'gtxy_weixin';
                    if($ways_type==62012){
                        $state['bank_type'] = 'gtxy_v2_weixin';
                    }
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;
                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/gtxy/weixin/oauth?state=' . $state);
                    return redirect($code_url);
                }

                
                //银盛 微信支付
                // TODO[银盛支付:微信入口]
                if ($ways_type == 14002) {
                    $state['bank_type'] = 'yinsheng_weixin';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/yinsheng/weixin/oauth?state=' . $state);
                    return redirect($code_url);
                }

                // TODO[东莞银行:微信入口]
                if ($ways_type == 40001) {
                    $state['bank_type'] = 'dongguan';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;
                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/dong_guan/weixin/oauth?query=' . $state);
                    return redirect($code_url);
                }

            }

            //京东
            if ($pay_type == 'jd') {
                //京东金融京东支付
                if ($ways_type == 6003) {
                    $data = $state;
                    return view('jd.jd', compact('data'));
                }

                //京东金融京东支付
                if ($ways_type == 15003) {
                    $data = $state;
                    return view('dlb.jd', compact('data'));
                }

                //威富通 京东支付
                if ($ways_type == 27003) {
                    $data = $state;
                    return view('wftpay.jd', compact('data'));
                }


                //威富通 京东支付
                if ($ways_type == 27103) {
                    $data = $state;
                    return view('wftpayv2.jd', compact('data'));
                }

                //汇旺财 京东支付s
                if ($ways_type == 28003) {
                    $data = $state;
                    return view('hwcpay.jd', compact('data'));
                }

            }

            //银联
            if ($pay_type == "unionpay") {
                //随行付支付 银联
                if ($ways_type == 13004) {
                    $userAuthCode = $request->get('userAuthCode');
                     $userAgent = $_SERVER['HTTP_USER_AGENT'];
                    error_log(date('Y-m-d H:i:s')." 【获取银联标志】： ".json_encode([$userAuthCode, $userAgent])."\n\n", 3, "/tmp/". 'get_un_openid'.date('Ymd').".log");

                    if ($userAuthCode) {
                        $config = new VbillConfigController();
                        $vbill_config = $config->vbill_config($store->config_id);
                        if (!$vbill_config) {
                            $message = "随行付配置不存在请检查配置~";

                            return view('errors.page_errors', compact('message'));
                        }
                        
                         $paymentApp = 'UnionPay/1.0 CloudPay';
                        if (strpos($_SERVER['HTTP_USER_AGENT'],'UnionPay/1.0 3999') !== false) {
                            $paymentApp = $_SERVER['HTTP_USER_AGENT'];
                        }

                        $un = [
                            'userAuthCode' => $userAuthCode,
                            'paymentApp' => $paymentApp,
                            'orgId' => $vbill_config->orgId,
                            'privateKey' => $vbill_config->privateKey,
                            'sxfpublic' => $vbill_config->sxfpublic
                        ];
                        $obj = new PayController();
                        $re = $obj->get_un_openid($un);

                        $open_id = isset($re['data']['respData']['data']) ? $re['data']['respData']['data'] : "";
                        if ($open_id == "") {
                            $message = "获取银联用户ID失败请稍后再试~";

                            return view('errors.page_errors', compact('message'));
                        }

                        $state['open_id'] = $open_id;
                    } else {
                        $url = $request->url() . '?store_id=' . $store_id;
                        $url = urlencode($url);
                        $url = "https://qr.95516.com/qrcGtwWeb-web/api/userAuth?version=1.0.0&redirectUrl=" . $url;

                        return redirect($url);
                    }
                    $data = $state;
                    $data['is_goods'] = Store::where('store_id',$store_id)->value('is_goods');
                    return view('vbill.un', compact('data'));
                }

                //随行付a支付 银联
                if ($ways_type == 19004) {
                    $userAuthCode = $request->get('userAuthCode');
                    Log::info('随行付a支付-银联-userAuthCode');
                    Log::info($userAuthCode);
                    if ($userAuthCode) {
                        $config = new VbillConfigController();
                        $vbill_config = $config->vbilla_config($store->config_id);
                        if (!$vbill_config) {
                            $message = "随行付a配置不存在请检查配置~";

                            return view('errors.page_errors', compact('message'));
                        }

                        $un = [
                            'userAuthCode' => $userAuthCode,
                            'paymentApp' => 'UnionPay/1.0 CloudPay',
                            'orgId' => $vbill_config->orgId,
                            'privateKey' => $vbill_config->privateKey,
                            'sxfpublic' => $vbill_config->sxfpublic
                        ];
                        $obj = new PayController();
                        $re = $obj->get_un_openid($un);
                        Log::info('随行付a支付-银联-获取用户id');
                        Log::info($re);
                        $open_id = isset($re['data']['respData']['data']) ? $re['data']['respData']['data'] : "";
                        if ($open_id == "") {
                            $message = "获取银联用户ID失败请稍后再试~";

                            return view('errors.page_errors', compact('message'));
                        }

                        $state['open_id'] = $open_id;
                    } else {
                        $url = $request->url() . '?store_id=' . $store_id;
                        $url = urlencode($url);
                        $url = "https://qr.95516.com/qrcGtwWeb-web/api/userAuth?version=1.0.0&redirectUrl=" . $url;
                        Log::info('随行付a支付-银联主扫');
                        Log::info($url);
                        return redirect($url);
                    }
                    $data = $state;
                    Log::info($data);
                    return view('vbilla.un', compact('data'));
                }

                //葫芦银联
                if ($ways_type == 23004) {
                    $userAuthCode = $request->get('userAuthCode');
                    if ($userAuthCode) {
                        $manager = new \App\Api\Controllers\Hltx\ManageController();
                        $hltx_merchant = $manager->pay_merchant($store_id, $store_pid);
                        $qd = $hltx_merchant->qd;
                        $hltx_config = $manager->pay_config($store->config_id, $qd);
                        if (!$hltx_config) {
                            $message = "hl支付配置不存在请检查配置~";

                            return view('errors.page_errors', compact('message'));
                        }
			
                        $manager->init($hltx_config);
                        if (!$hltx_merchant || empty($hltx_merchant->mer_no)) {
                            return json_encode([
                                'status' => 2,
                                'message' => 'hl商户未成功开通通道!'
                            ]);
                        }
                        $merNo = $hltx_merchant->mer_no;
                        $re = $manager->get_openid($merNo, $userAuthCode);
                        if ($re['status'] == 0) {
                            $message = $re['message'];

                            return view('errors.page_errors', compact('message'));
                        }

                        $open_id = isset($re['data']['userId']) ? $re['data']['userId'] : "";
                        if ($open_id == "") {
                            $message = "获取银联用户ID失败请稍后再试~";

                            return view('errors.page_errors', compact('message'));
                        }
			
                        $state['open_id'] = $open_id;
                    } else {
                        $url = $request->url() . '?store_id=' . $store_id;
                        $url = urlencode($url);
                        $url = "https://qr.95516.com/qrcGtwWeb-web/api/userAuth?version=1.0.0&redirectUrl=" . $url;

                        return redirect($url);
                    }
                    $data = $state;

                    return view('hltx.un', compact('data'));
                }

                //联动优势 银联
                if ($ways_type == 5004) {
                    // $respCode = $request->get('respCode'); //银联标识
                    
                    // file_put_contents('1109.log', var_export($respCode, true) . "\r\n", FILE_APPEND);
                    // print_r($respCode);die;
                    
                    // if ($respCode == '00') { //获取用户信息成功
                        // $userAuthCode = $request->get('userAuthCode'); //用户标识,银联二维码上传userAuthCode
                        // if ($userAuthCode) {
                        //     $state['open_id'] = $userAuthCode;
                        // } else {
                        //     $url = $request->url() . '?store_id=' . $store_id;
                        //     $url = urlencode($url);
                        //     $url = "https://qr.95516.com/qrcGtwWeb-web/api/userAuth?version=1.0.0&redirectUrl=" . $url;
                        //     return redirect($url);
                        // }
                        
                        $state['open_id'] = '123';
                        $data = $state;

                        return view('linkage.un', compact('data'));
                    // }

                    // if ($respCode != '00' && $respCode != '34') { //获取用户信息失败
                    //     $message = "联动优势-云闪付-用户授权失败";
                    //     return view('errors.page_errors', compact('message'));
                    // }
                }

                //威富通 银联
                if ($ways_type == 27004) {
                    
                    $respCode = $request->get('respCode'); //银联标识
                    // if ($respCode == '00') { //获取用户信息成功
                    //     $userAuthCode = $request->get('userAuthCode'); //用户标识,银联二维码上传userAuthCode
                    //     if ($userAuthCode) {
                    //         $state['open_id'] = $userAuthCode;
                    //     } else {
                    //         $url = $request->url() . '?store_id=' . $store_id;
                    //         $url = urlencode($url);
                    //         $url = "https://qr.95516.com/qrcGtwWeb-web/api/userAuth?version=1.0.0&redirectUrl=" . $url;
                    //         return redirect($url);
                    //     }
                        $state['open_id'] = '123';
                        $data = $state;
                        
                        return view('wftpay.un', compact('data'));
                    // }

                    // if ($respCode != '00' && $respCode != '34') { //获取用户信息失败
                    //     $message = "威富通-云闪付-用户授权失败";
                    //     return view('errors.page_errors', compact('message'));
                    // }
                }

                if ($ways_type == 27104) {

                    $respCode = $request->get('respCode'); //银联标识
                    // if ($respCode == '00') { //获取用户信息成功
                    //     $userAuthCode = $request->get('userAuthCode'); //用户标识,银联二维码上传userAuthCode
                    //     if ($userAuthCode) {
                    //         $state['open_id'] = $userAuthCode;
                    //     } else {
                    //         $url = $request->url() . '?store_id=' . $store_id;
                    //         $url = urlencode($url);
                    //         $url = "https://qr.95516.com/qrcGtwWeb-web/api/userAuth?version=1.0.0&redirectUrl=" . $url;
                    //         return redirect($url);
                    //     }
                    $state['open_id'] = '123';
                    $data = $state;

                    return view('wftpayv2.un', compact('data'));
                    // }

                    // if ($respCode != '00' && $respCode != '34') { //获取用户信息失败
                    //     $message = "威富通-云闪付-用户授权失败";
                    //     return view('errors.page_errors', compact('message'));
                    // }
                }
                //汇旺财 银联
                if ($ways_type == 28004) {
                    $respCode = $request->get('respCode'); //银联标识
                    if ($respCode == '00') { //获取用户信息成功
                        $userAuthCode = $request->get('userAuthCode'); //用户标识,银联二维码上传userAuthCode
                        if ($userAuthCode) {
                            $state['open_id'] = $userAuthCode;
                        } else {
                            $url = $request->url() . '?store_id=' . $store_id;
                            $url = urlencode($url);
                            $url = "https://qr.95516.com/qrcGtwWeb-web/api/userAuth?version=1.0.0&redirectUrl=" . $url;
                            return redirect($url);
                        }
                        $data = $state;

                        return view('hwcpay.un', compact('data'));
                    }

                    if ($respCode != '00' && $respCode != '34') { //获取用户信息失败
                        $message = "汇旺财-云闪付-用户授权失败";
                        return view('errors.page_errors', compact('message'));
                    }
                }
                //翼支付银联
                if ($ways_type == 30052) {
                    $state['bank_type'] = 'wingpay';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/vbill/weixin/unwingpay?state=' . $state);
                    return redirect($code_url);
                }
                //平安银行银联
                if ($ways_type == 30013) {
                    $state['bank_type'] = 'safepay';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/vbill/weixin/unsafepay?state=' . $state);
                    return redirect($code_url);
                }
                
                //邮储银行银联
                if ($ways_type == 26004) {
                    $state['bank_type'] = 'youpay';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/vbill/weixin/unyoupay?state=' . $state);
                    return redirect($code_url);
                }
                
                //工行 银联
                if ($ways_type == 20004) {
                    $state['open_id'] = '12223';
                    $data = $state;

                    return view('vbill.icbc_un', compact('data'));
                }
                
                 //银卡
                if ($ways_type == 38003) {
                    $state['bank_type'] = 'yinka';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/yinka/unionpay?state=' . $state);
                    return redirect($code_url);
                }
                //民生银行银联
                if ($ways_type == 50003) {
                    $state['bank_type'] = 'cmbc';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/cmbc/unionpay?state=' . $state);
                    return redirect($code_url);
                }
                //国通银联
                if (in_array($ways_type,[62004,62014])) {
                    $state['bank_type'] = 'gtxy';
                    if($ways_type==62014){
                        $state['bank_type'] = 'gtxy_v2';
                    }
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/gtxy/unionpay?state=' . $state);
                    return redirect($code_url);
                }
                  //兴业银行银联
                if ($ways_type == 39003) {
                    $state['bank_type'] = 'cib';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/cib/weixin/unyoupay?state=' . $state);
                    return redirect($code_url);
                }
                
                // TODO[银盛支付:银联入口]
                if ($ways_type == 14004) {
                    $state['bank_type'] = 'yinsheng_unionpay';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/yinsheng/un_pay?state=' . $state);
                    return redirect($code_url);
                }

                // TODO[东莞银行:银联入口]
                if ($ways_type == 40003) {
                    $state['bank_type'] = 'dongguan_unionpay';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;
                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/dong_guan/un_pay?query=' . $state);
                    return redirect($code_url);
                }

            }
            
            if ($pay_type == "Bestpay"){
                //翼支付支付
                if ($ways_type == 30053) {
                    $state['bank_type'] = 'wingpay';
                    $state['scope_type'] = 'snsapi_base';
                    $state['config_id'] = $store->config_id;

                    $state = \App\Common\TransFormat::encode($state);
                    $code_url = url('api/vbill/weixin/wingpay?state=' . $state);
                    return redirect($code_url);
                }
            }

            return $this->qr_aggs($pay_type, $StorePayWay, $store, $state);

            $message = "您使用的客户端与要求不符~";
            return view('errors.page_errors', compact('message'));
        } else {
            $message = "  二维码没有绑定激活";
            return view('errors.page_errors', compact('message'));
        }
    }

    public function qr_aggs ($pay_type, $StorePayWay, $store, $state)
    {
        $company = $StorePayWay->company;
        if ($pay_type == 'weixin') {
            $config = new WeixinConfigController();
            $WeixinConfig = $config->weixin_config_obj($store->config_id);
            $state['bank_type'] = $company.'_weixin';
            $state['scope_type'] = 'snsapi_base';
            $state['config_id'] = $store->config_id;
            $state['authorizer_appid'] = $WeixinConfig->authorizer_appid;
            $state['authorizer_refresh_token'] = $WeixinConfig->authorizer_refresh_token;
            $state = \App\Common\TransFormat::encode($state);
            $code_url = url('api/'.$company.'/weixin/oauth?state=' . $state);

            return redirect($code_url);
        }
        if ($pay_type == 'alipay') {
            $isvconfig = new AlipayIsvConfigController();
            $config = $isvconfig->AlipayIsvConfig($store->config_id);
            $state['bank_type'] = $company.'_alipay';
            $state = \App\Common\TransFormat::encode($state);
            $app_auth_url = $config->alipay_app_authorize;
            $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;
            return redirect($code_url);
        }
        if ($pay_type == 'unionpay') {
            $state['bank_type'] = $company.'_union';
            $state['scope_type'] = 'snsapi_base';
            $state['config_id'] = $store->config_id;

            $state = \App\Common\TransFormat::encode($state);
            $code_url = url('api/'.$company.'/unionpay?state=' . $state);
            return redirect($code_url);
        }
        $message = "您使用的客户端与要求不符1~";
        return view('errors.page_errors', compact('message'));

    }

    public function qr_code_hb(Request $request)
    {
        $pay_type = "";
        $id = $request->get('id', '');//门店ID

        //判断是不是微信
        if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
            $pay_type = 'weixin';
        }

        //判断是不是支付宝
        if (strpos($_SERVER['HTTP_USER_AGENT'], 'AlipayClient') !== false) {
            $pay_type = 'alipay';
        }

        //判断是不是翼支付
        if (strpos($_SERVER['HTTP_USER_AGENT'], 'Bestpay') !== false) {
            $pay_type = 'Bestpay';
        }

        //判断是不是京东
        if (strpos($_SERVER['HTTP_USER_AGENT'], 'WalletClient') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'JDJR-App') !== false) {
            $pay_type = 'jd';
        }

        if (strpos($_SERVER['HTTP_USER_AGENT'], 'WalletClient') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'jdapp') !== false) {
            $pay_type = 'jd';
        }

        $QrCodeHb = QrCodeHb::where('id', $id)->first();
        if (!$QrCodeHb) {
            $message = "  二维码ID不正确";
            return view('errors.page_errors', compact('message'));
        }

        if ($pay_type == "alipay") {
            return redirect($QrCodeHb->ali_url);
        }
        elseif ($pay_type == "weixin") {
            $url = $url = $QrCodeHb->wx_url;
            $url = "http://qr.topscan.com/api.php?text=" . $url;
            return redirect($url);
        }
        else {
            $url = url('/qr_code_hb?id=') . $id;

            //方式2
            $url = url('/qr_code_hb?id=') . $id;
            $url = "http://qr.topscan.com/api.php?text=" . $url;
            return redirect($url);
        }
    }
    
    public function merch_qr(Request $request){
        $store_id = $request->get('store_id', '');
        if ($store_id == "") {
            $message = "门店ID不能为空";
            return view('errors.page_errors', compact('message'));
        }
        if ($store_id) {
            $pay_type = "unionpay";
            //判断是不是微信
            if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
                $pay_type = 'weixin';
            }

            //判断是不是支付宝
            if (strpos($_SERVER['HTTP_USER_AGENT'], 'AlipayClient') !== false) {
                $pay_type = 'alipay';
            }

            //判断是不是翼支付
            if (strpos($_SERVER['HTTP_USER_AGENT'], 'Bestpay') !== false) {
                $pay_type = 'Bestpay';
            }
            

            //判断是不是京东
            if (strpos($_SERVER['HTTP_USER_AGENT'], 'WalletClient') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'JDJR-App') !== false) {
                $pay_type = 'jd';
            }

            if (strpos($_SERVER['HTTP_USER_AGENT'], 'WalletClient') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'jdapp') !== false) {
                $pay_type = 'jd';
            }


            $store = Store::where('store_id', $store_id)
                    ->select('config_id', 'user_id', 'pid', 'merchant_id', 'store_short_name', 'store_address')
                    ->first();
            if (!$store) {
                $message = "门店不存在";
                return view('errors.page_errors', compact('message'));
            }

            $user_id = $store->user_id;
            $user = User::where('id', $user_id)->select('id', 'is_delete')->first();
            if (!$user ||$user->is_delete) {
                $message = "业务员被删除，请联系归属业务员";

                return view('errors.page_errors', compact('message'));
            }
            // //商户id为空
            $merchant_id='';
            if ($merchant_id == "") {
                $merchant_id = $store->merchant_id;
            }
            $other_no='';
            $notify_url='';
            $store_pid= $store->pid;
            //配置
            $state = [
                'store_id' => $store_id,
                'store_name' => $store->store_short_name,
                'store_address' => $store->store_address,
                'config_id' => $store->config_id,
                'merchant_id' => $merchant_id,
                'auth_type' => '02',
                'other_no' => $other_no,
                'notify_url' => $notify_url,
                'store_pid' => $store_pid
            ];
            //支付宝
            if ($pay_type == 'alipay') {
                $isvconfig = new AlipayIsvConfigController();
                $config = $isvconfig->AlipayIsvConfig($store->config_id);
                $state['bank_type'] = 'vbill1_alipay';
                $state = \App\Common\TransFormat::encode($state);
                $app_auth_url = $config->alipay_app_authorize;
                $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;
                return redirect($code_url);
            }
            
            //微信
            if ($pay_type == 'weixin') {
                $config = new WeixinConfigController();
                $WeixinConfig = $config->weixin_config_obj($store->config_id);
                $state['bank_type'] = 'vbill1_weixin';
                $state['scope_type'] = 'snsapi_base';
                $state['config_id'] = $store->config_id;
                $state = \App\Common\TransFormat::encode($state);
                $code_url = url('api/vbill/weixin/storelist?state=' . $state);
                return redirect($code_url);
            }

            $message = "您使用的客户端与要求不符~";
            return view('errors.page_errors', compact('message'));
        } else {
            $message = "  二维码没有绑定激活";
            return view('errors.page_errors', compact('message'));
        }
    }
    
    public function user_qr(Request $request){
        $user_id = $request->get('user_id', '');
        if ($user_id == "") {
            $message = "渠道编号不能为空";
            return view('errors.page_errors', compact('message'));
        }
        if ($user_id) {
            $pay_type = "unionpay";
            //判断是不是微信
            if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
                $pay_type = 'weixin';
            }

            //判断是不是支付宝
            if (strpos($_SERVER['HTTP_USER_AGENT'], 'AlipayClient') !== false) {
                $pay_type = 'alipay';
            }

            //判断是不是翼支付
            if (strpos($_SERVER['HTTP_USER_AGENT'], 'Bestpay') !== false) {
                $pay_type = 'Bestpay';
            }
            

            //判断是不是京东
            if (strpos($_SERVER['HTTP_USER_AGENT'], 'WalletClient') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'JDJR-App') !== false) {
                $pay_type = 'jd';
            }

            if (strpos($_SERVER['HTTP_USER_AGENT'], 'WalletClient') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'jdapp') !== false) {
                $pay_type = 'jd';
            }
            
            $state = [
                'store_name' => '平安财务对账后台',
            ];
            //支付宝
            // if ($pay_type == 'alipay') {
            //     $isvconfig = new AlipayIsvConfigController();
            //     $config = $isvconfig->AlipayIsvConfig($store->config_id);
            //     $state['bank_type'] = 'vbill1_alipay';
            //     $state = \App\Common\TransFormat::encode($state);
            //     $app_auth_url = $config->alipay_app_authorize;
            //     $code_url = $app_auth_url . '?app_id=' . $config->app_id . "&redirect_uri=" . $config->callback . '&scope=auth_base&state=' . $state;
            //     return redirect($code_url);
            // }
            
            //微信
            if ($pay_type == 'weixin') {
                $config = new WeixinConfigController();
                $WeixinConfig = $config->weixin_config_obj(1234);
                $state['bank_type'] = 'vbill1_weixin';
                $state['scope_type'] = 'snsapi_base';
                $state['config_id'] = '1234';
                $state['open_id'] = '1234';
                $state['user_id'] = $user_id;
                $state = \App\Common\TransFormat::encode($state);
                $code_url = url('api/vbill/weixin/user_payqr?state=' . $state);
                return redirect($code_url);
            }

            $message = "您使用的客户端与要求不符~";
            return view('errors.page_errors', compact('message'));
        } else {
            $message = "  二维码没有绑定激活";
            return view('errors.page_errors', compact('message'));
        }
    }
    
    public function store_list(Request $request){
        $user_id = $request->get('user_id', '');
        $code_url = url('api/vbill/storelist');
        return redirect($code_url);
    }


}
